/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 * Origin source from MaNGOS(GPL2).
 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
 */

#ifndef __MAP_REFERENCE_H__
#define __MAP_REFERENCE_H__

#include "Reference.h"
#include "Map.h"

namespace PQServiceCore
{

	class MapReference 
		: public Reference<Map, Player>
	{
		protected:
			void targetObjectBuildLink()
			{
				// called from link()
				getTarget()->_mapRefManager.insertFirst(this);
				getTarget()->_mapRefManager.incSize();
			}

			void targetObjectDestroyLink()
			{
				// called from unlink()
				if(isValid()){
					getTarget()->_mapRefManager.decSize();
				}

			}

			void sourceObjectDestroyLink()
			{
				// called from invalidate()
				getTarget()->_mapRefManager.decSize();
			}

		public:
			MapReference() : Reference<Map, Player>() {}
			~MapReference() { unlink(); }
			MapReference *next() { return (MapReference*)Reference<Map, Player>::next(); }
			MapReference const *next() const { return (MapReference const*)Reference<Map, Player>::next(); }
			MapReference *nockeck_prev() { return (MapReference*)Reference<Map, Player>::nocheck_prev(); }
			MapReference const *nocheck_prev() const { return (MapReference const*)Reference<Map, Player>::nocheck_prev(); }
	};
}

#endif
